package com.xianyun.book.convertor;

import com.xianyun.book.domain.user.AccountStatus;
import com.xianyun.book.domain.user.Gender;
import com.xianyun.book.domain.user.Identity;
import com.xianyun.book.domain.user.SystemUser;
import com.xianyun.book.gatewayimpl.database.dataobject.UserDO;

/**
 * 用户转换器
 * @author macos-zyj
 */
public class UserConvertor {
    public static SystemUser toDomain(UserDO userDO){
        SystemUser domainObject = new SystemUser();
        domainObject.setId(userDO.getId());
        domainObject.setUserName(userDO.getUserName());
        domainObject.setAvatarUrl(userDO.getAvatarUl());
        domainObject.setNickName(userDO.getNickName());
        domainObject.setBirthday(userDO.getBirthday());
        domainObject.setPassword(userDO.getPassword());
        domainObject.setMobile(userDO.getMobile());
        domainObject.setEmail(userDO.getEmail());
        domainObject.setCity(userDO.getCity());
        domainObject.setProvince(userDO.getProvince());
        domainObject.setCountry(userDO.getCountry());
        domainObject.setIdentity(Identity.getIdentity(userDO.getIdentity()));
        domainObject.setGender(Gender.getGenderType(userDO.getGender()));
        domainObject.setAccountStatus(AccountStatus.getAccountStatus(userDO.getAccountStatus()));
        domainObject.setCreateTime(userDO.getCreateTime());
        domainObject.setUpdateTime(userDO.getUpdateTime());
        return domainObject;
    }

    public static UserDO toDataObject(SystemUser systemUser){
        UserDO dataObject = new UserDO();
        dataObject.setId(systemUser.getId());
        dataObject.setUserName(systemUser.getUserName());
        dataObject.setAvatarUl(systemUser.getAvatarUrl());
        dataObject.setNickName(systemUser.getNickName());
        dataObject.setBirthday(systemUser.getBirthday());
        dataObject.setPassword(systemUser.getPassword());
        dataObject.setMobile(systemUser.getMobile());
        dataObject.setEmail(systemUser.getEmail());
        dataObject.setCity(systemUser.getCity());
        dataObject.setProvince(systemUser.getProvince());
        dataObject.setCountry(systemUser.getCountry());
        dataObject.setIdentity(systemUser.getIdentity().name());
        dataObject.setGender(systemUser.getGender().getGender());
        dataObject.setAccountStatus(systemUser.getAccountStatus().name());
        dataObject.setCreateTime(systemUser.getCreateTime());
        dataObject.setUpdateTime(systemUser.getUpdateTime());
        return dataObject;
    }
}
